package cn.yunhe.controller;

import cn.yunhe.biz.IDeptBiz;
import cn.yunhe.model.Dept;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
@Controller
@Scope(value="prototype")
@ParentPackage(value="struts-default")
public class DeptAction extends ActionSupport{

    @Resource(name = "deptBiz")
    private IDeptBiz deptBiz;


    private String dname;
    private String loc;

    public String queryAllDept() {
        List<Dept> list = deptBiz.queryAllDept();
        System.out.println("action执行了dept_list方法=====");
        Map map = (Map) ActionContext.getContext().get("request");
        map.put("list",list);
        return SUCCESS;
    }

    public String addDept(){
        deptBiz.addDept(new Dept(dname,loc));
        System.out.println("action执行了addDept方法");
        return SUCCESS;
    }

    public String delDept(){
        Dept dept = new Dept();
        dept.setDeptid(5);
        deptBiz.delDept(dept);
        return SUCCESS;
    }
    public IDeptBiz getDeptBiz() {
        return deptBiz;
    }

    public void setDeptBiz(IDeptBiz deptBiz) {
        this.deptBiz = deptBiz;
    }

    public String getDname() {
        return dname;
    }

    public void setDname(String dname) {
        this.dname = dname;
    }

    public String getLoc() {
        return loc;
    }

    public void setLoc(String loc) {
        this.loc = loc;
    }
}
